package com.zrs.gmall.web;

import com.zrs.gmall.product.client.ProductFeignClient;
import com.zrs.gmall.product.model.SkuInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * @author: zrs
 * @create: 2023-03-08
 */
@Controller
public class CartController {

    @Autowired
    private ProductFeignClient productFeignClient;

    /**
     * 渲染商品加购成功页面
     * @param model
     * @param skuId
     * @param skuNum
     * @return
     */
    @GetMapping("/addCart.html")
    public String addCartHtml(Model model, @RequestParam("skuId") Long skuId, @RequestParam("skuNum") Integer skuNum) {
        //远程调用商品微服务获取商品信息
        SkuInfo skuInfo = productFeignClient.getSkuInfoAndImages(skuId);
        model.addAttribute("skuInfo", skuInfo);
        model.addAttribute("skuNum", skuNum);
        //渲染加购成功页面
        return "/cart/addCart";
    }


    /**
     * 渲染购物车列表页面
     * @return
     */
    @GetMapping("/cart.html")
    public String cartListHtml(){
        return "/cart/index.html";
    }

}
